package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.log.anno.SystemOperLog;
import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductSaveDTO;
import com.atguigu.spzx.model.dto.product.ProductSearchDTO;
import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.product.ProductVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2024-03-18-20:52
 */
@RestController
@RequestMapping("/admin/product/product")
@Tag(name = "商品管理")
public class ProductController {

    @Resource
    ProductService productService;

    @SystemOperLog(title = "商品管理模块")
    @GetMapping("{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize,
                       ProductSearchDTO productSearchDTO){
        PageInfo<ProductVo> pageInfo = productService.list(pageNum,pageSize,productSearchDTO);
        return Result.ok(pageInfo);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        productService.deleteById(id);
        return Result.ok();
    }

    @PostMapping("/save")
    public Result saveProduct(@RequestBody ProductSaveDTO productSaveDTO){
        productService.saveProduct(productSaveDTO);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        ProductSaveDTO productSaveDTO = productService.getById(id);
        return Result.ok(productSaveDTO);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSaveDTO productSaveDTO){
        productService.updateById(productSaveDTO);
        return Result.ok();
    }

    //审批
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id")Long id,
                                    @PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.ok();
    }
    //上下架
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id")Long id,
                                    @PathVariable("status")Integer status){
        productService.updateStatus(id,status);
        return Result.ok();
    }

}
